#!/usr/bin/env python
# encoding: utf-8
"""
#-------------------------------------------------------------------#
#                   CONFIDENTIAL --- CUSTOM STUDIOS                 #     
#-------------------------------------------------------------------#
#                                                                   #
#                   @Project Name : Globallawonline                #
#                                                                   #
#                   @File Name    : changedate.py                      #
#                                                                   #
#                   @Programmer   : 李建                            #
#                                                                   #  
#                   @Start Date   : 2021/6/15 17:32                 #
#                                                                   #
#                   @Last Update  : 2021/6/15 17:32                 #
#                                                                   #
#-------------------------------------------------------------------#
# Classes:修改13年之前判例的状态为不校对                                                          #
#                                                                   #
#-------------------------------------------------------------------#
"""
import re

import pymysql

from Seetings import JGMYSQL_CONNEXT

jg_conn = pymysql.connect(host=JGMYSQL_CONNEXT["MYSQL_HOST"],
                          port=JGMYSQL_CONNEXT["MYSQL_PORT"],
                          db=JGMYSQL_CONNEXT["MYSQL_DB"],
                          user=JGMYSQL_CONNEXT["MYSQL_USER"],
                          passwd=JGMYSQL_CONNEXT["MYSQL_PASSWD"],
                          charset=JGMYSQL_CONNEXT["MYSQL_CHARSET"])
jg_cursor = jg_conn.cursor()
changsysid = []
sql = '''SELECT sysid,AdjudicationDateStr FROM `case` WHERE SortA = "LAWCOUNTRYFLB" AND SYS_FLD_MARKSTATE = "2" AND AdjudicationDateStr REGEXP "[0-9]{4}"'''
try:
    jg_cursor.execute(sql)
    trs = jg_cursor.fetchall()
except Exception as e:
    print(str(e))
for tr in  trs:
    years = re.findall("\d{4}", tr[1])
    if len(years):
        year = int(years[0])
        if year < 2013:
            changsysid.append(tr[0])
for sysid in changsysid:
    sql = '''UPDATE `case` SET SYS_FLD_MARKSTATE = "10" where sysid = "%s"''' % sysid
    try:
        jg_cursor.execute(sql)
    except Exception as e:
        with open("sysiderro.txt", "a+", encoding='utf-8') as f:
            f.write(sysid + "\n")
        print("%s更新状态出错:%s" % (sysid, str(e)))
jg_conn.commit()
jg_cursor.close()
jg_conn.close()
